<template>
  <div>
    <el-form :model="formdata" label-width="120px" size="mini">
      <el-row>
        <el-col :span="5">&nbsp;</el-col>
        <el-col :span="6">
          <el-form-item label="操作员：">
            <el-input v-model="formdata.creator" disabled></el-input>
          </el-form-item>
          <el-form-item label="备注：">
            <el-input v-model="formdata.remark" type="textarea" maxlength="50" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="商品总计：" prop="priceTotal">
            <el-input v-model="formdata.saleAmount" disabled></el-input>
          </el-form-item>
          <el-form-item label="运费：" prop="freight">
            <sd-input :val.sync='formdata.freight' :disableds="disableds"></sd-input>
            <!-- <el-input v-model="formdata.freight" type="text" disabled></el-input> -->
          </el-form-item>
          <el-form-item label="应付总计：">
            <el-input v-model="formdata.amount" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="!hasConfirmCai">
          <el-form-item label="确认商品总计：" prop="priceTotal">
            <el-input v-model="confirmSaleAmount" disabled></el-input>
          </el-form-item>
          <el-form-item label="确认运费：" prop="confirmFreight">
            <sd-input :val.sync='formdata.confirmFreight' :disableds="isConfirm"></sd-input>
            <!-- <el-input v-model="formdata.confirmFreight" type="text" :disabled="isConfirm"></el-input> -->
          </el-form-item>
          <el-form-item label="确认应付总计：">
            <el-input v-model="confirmformdataAllTotal" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="1">&nbsp;</el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import sdInput from "@/components/SdInput";
export default {
  data() {
    return {
      disableds: true
    };
  },
  components: { sdInput },
  props: {
    formdata: {
      type: Object,
      default: {},
      required: true
    },
    tableData: {
      type: Array,
      default: [],
      required: true
    },
    isConfirm: {
      type: Boolean,
      default: true,
      required: true
    },
    hasConfirmCai: {
      type: Boolean,
      default: false,
      required: true
    }
  },
  computed: {
    saleAmount: function() {
      let totalPrice = 0;
      this.tableData.forEach(i => {
        i.goodsAmount = i.goodsPrice * i.goodsNum;
        totalPrice += i.goodsPrice * i.goodsNum;
      });
      this.formdata.purchaseAmount = totalPrice.toFixed(2);
      return isNaN(totalPrice) ? 0 : totalPrice.toFixed(2);
    },
    formdataAllTotal: function() {
      let totalPrice = 0;
      totalPrice = Number(this.saleAmount) + Number(this.formdata.freight);
      if (totalPrice == NaN || totalPrice == 0) {
        this.formdata.amount = 0;
        return totalPrice;
      } else {
        this.formdata.amount = totalPrice.toFixed(2);
        return totalPrice.toFixed(2);
      }
    },
    confirmSaleAmount: function() {
      let totalPrice = 0;
      this.freightNum = 0.0;
      this.tableData.forEach(i => {
        totalPrice += i.goodsPrice * i.confirmNum;
         if(i.freight==undefined){
            i.freight=0
          }
          this.freightNum += i.freight * i.confirmNum;
      });
      this.formdata.confirmFreight = isNaN(this.freightNum) ? 0:this.freightNum.toFixed(2);
      this.formdata.confirmSaleAmount = totalPrice.toFixed(2);
      return isNaN(totalPrice) ? 0 : totalPrice.toFixed(2);
    },
    confirmformdataAllTotal: function() {
      let totalPrice = 0;
      totalPrice =
        Number(this.confirmSaleAmount) + Number(this.formdata.confirmFreight);
      if (totalPrice == NaN || totalPrice == 0) {
        this.formdata.confirmAmount = 0;
        return totalPrice;
      } else {
        this.formdata.confirmAmount = totalPrice.toFixed(2);
        return totalPrice.toFixed(2);
      }
    }
  }
};
</script>
